#!/usr/bin/env python
#coding=utf-8 

# 集合
s = set('cheeseshop')
print s
t = frozenset('bookshop')  # 不可变集合
print t
print type(s)
print type(t)

print 'k' in s
#s.add('z')
s.update('pypi')
print s
s -= set('pypi')
print s


print s | t # 联合
print s & t # 交集
print s - t # 差集
print s ^ t # 异或

# elif == else if

# 三元运算符号  A if 条件 else B  成立 返回A不成立返回B
x,y = 3,4
print x if x < y else y


# for循环本质
seq = ['i', 'love', 'you']
for i in seq:
	print i,
print
fetch = iter(seq)
while True:
	try:
		i = fetch.next()
	except StopIteration:
		break
	print i,
print

legends = {('poe', 'auther') :(1809,1849,1976),
('Gaudi', 'architect'):(1856, 1906, 1987),
('Freud', 'psychoanalyst'):(1856, 1939, 1990)}
for eachLegend in legends:
	print "name: %s\tOccupation: %s" % eachLegend
	print '    Birth: %s\tDeath: %s\t Album: %s\n'\
	% legends[eachLegend]

# 列表解析
print map(lambda x: x ** 2, range(6))
print [x ** 2 for x in range(6)] #  操作  for  x in 序列
# 高级版本 操作 for x in 序列 if 条件满足
seq = range(30)
print filter(lambda x: x % 2, seq)
print [x for x in seq if x % 2 != 0]

# 简单矩阵
print [(x+1, y+1) for x in range(3) for y in range(5)]

# 生成器 具有延迟计算的作用  对于  大文件内存无法已下载读取的文件比较有效率
# sum(len(word) for line in data for word in line.split())

def cols():
	yield 56
	res = yield 2
	print '*'*20
	print res
	print '*'*20
	yield 1
	
g = cols()
print next(g)
print next(g)
print g.send(7) # 传入参数




